package com.google.code.contactserv.util;
/*
*       Copyright 2007 The semap project development team.
*
*       Licensed under the Apache License, Version 2.0 (the "License");
*       you may not use this file except in compliance with the License.
*       You may obtain a copy of the License at
*
*               http://www.apache.org/licenses/LICENSE-2.0
*
*       Unless required by applicable law or agreed to in writing, software
*       distributed under the License is distributed on an "AS IS" BASIS,
*       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*       See the License for the specific language governing permissions and
*       limitations under the License.
*
*       Created by ${user} at ${date} ${time}.
*
*       ${description}.
*
*       $Id$
*/

import java.net.URL;

public final class SystemUtils {

    private final static String WIN_ID = "Windows";

    private static final String WINDOWS_OS_NAME = "Windows";
    private static final String WINDOWS_SHELL = "cmd /c ";

    private static final String UNIX_OS_NAME = "Unix";
    private static final String UNIX_SHELL = "";

    private SystemUtils() {
    }

    /**
     * Try to determine whether this application is running under Windows * or
     * some other platform by examing the "os.name" property.
     *
     * @return true if this application is running under a Windows OS
     */
    public static boolean isWindowsPlatform() {
        String os = System.getProperty("os.name");
        return os != null && os.startsWith(WIN_ID);
    }

    public static String getOSName() {
        return isWindowsPlatform() ? WINDOWS_OS_NAME : UNIX_OS_NAME;
    }

    public static String getOSCMD() {
        return isWindowsPlatform() ? WINDOWS_SHELL : UNIX_SHELL;
    }

    public static String getFileSeparator() {
        return System.getProperty("file.separator");
    }

    /**
     * @param aClass class object
     * @return an absolute path to the .class file
     */
    public static URL getResourceURLByClass(Class aClass) {
        return SystemUtils.class.getResource("/" + aClass.getName().replace('.', '/') + ".class");
    }

    public static Object getInstance(String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return Class.forName(className).newInstance();
    }
}
